<!DOCTYPE html>
<html lang="en">

  <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
  </head>

  <body>


    <script>
      axios.interceptors.request.use(config => {
      // Do something before request is sent
      config.headers.Authorization = `JWT ${window.localStorage.getItem('token') | ''}`;
      return config;
      }, error => {
      // Do something with request error
      return Promise.reject(error);
      });

      //http response 拦截器
      axios.interceptors.response.use(
        undefined,
        error => {
          let res = error.response;
          switch (res.status) {

            case 401:
              // 返回 401 清除token信息并跳转到登录页面
              // store.commit(types.LOGOUT);
              //router.replace({
              // path: '/app/login',
              // query: {redirect: router.currentRoute.fullPath}
              //})
              return Promise.reject({
                "detail": '未登录 或者token过期'
              })
              console.log('未登录 或者token过期');
            case 403:
              console.log('您没有该操作权限');
              return Promise.reject({
                "detail": "您没有该操作权限"
              })
              // alert('您没有该操作权限');
            case 500:
              console.log('服务器错误');
              return Promise.reject({
                "detail": "服务器错误"
              })
              // alert('服务器错误');
          }
          //return Promise.reject(error.response.data) // 返回接口返回的错误信息
        });


      axios.get("http://172.16.1.97:8000/goods", {
          headers: {
            "Authorization": `JWT ${this.mytoken}`
          }
        })
        .then(res => {
          console.log(res.status)
          console.log(res.data)
        })
        .catch(err => {
          console.error(err);
          this.$notify({
            message: err.detail,
            type: "warning"
          })
        })

    </script>
  </body>

</html>
